package com.example.weather_plus.data.repository;

import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import com.example.weather_plus.data.model.AQIInfo;
import com.example.weather_plus.data.model.CityInfo;
import com.example.weather_plus.data.model.DailyForecastInfo;
import com.example.weather_plus.data.model.HourlyForecastInfo;
import com.example.weather_plus.data.model.WeatherInfo;
import com.example.weather_plus.data.network.GeoApiService;
import com.example.weather_plus.data.network.WeatherApiService;
import com.example.weather_plus.data.retrofit.RetrofitClient;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


public class GeoRepository {
    private final GeoApiService apiService;

    public GeoRepository() {
        String baseUrl = "https://geoapi.qweather.com/v2/";
        RetrofitClient client = new RetrofitClient();
        apiService = client.getInstance(baseUrl).create(GeoApiService.class);
    }

    public LiveData<CityInfo> fetchCityInfo(String locationId, String apiKey) {
        final MutableLiveData<CityInfo> data = new MutableLiveData<>();
        apiService.getCityInfo(locationId, apiKey).enqueue(new Callback<CityInfo>() {
            @Override
            public void onResponse(@NonNull Call<CityInfo> call, @NonNull Response<CityInfo> response) {
                if (response.isSuccessful() && response.body() != null) {
                    data.postValue(response.body());
                } else {
                    // Handle error, e.g., set error state in LiveData
                }
            }

            @Override
            public void onFailure(Call<CityInfo> call, Throwable t) {
                // Handle failure, e.g., set error state in LiveData
            }
        });
        return data;
    }

}